package com.ant.storage.service.impl;

import com.ant.storage.common.ResultCode;
import com.ant.storage.dto.AccountNumberDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.mapper.AccountNumberMapper;
import com.ant.storage.pojo.AccountNumber;
import com.ant.storage.service.IAccountNumberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author melon
 * @since 2024-06-05
 */
@Service
public class AccountNumberServiceImpl extends ServiceImpl<AccountNumberMapper, AccountNumber> implements IAccountNumberService {

    @Override
    public  PageInfo<AccountNumber> queryList(AccountNumberDto dto) {
        try {
            PageHelper.startPage(dto.getPageIndex(), dto.getPageSize());
            QueryWrapper<AccountNumber> wrapper = new QueryWrapper<>();
            wrapper.orderByAsc("id");
            PageInfo<AccountNumber> info = new PageInfo<>(this.baseMapper.selectList(wrapper));
            return info;
        } catch (Exception e) {
            throw new AntException(ResultCode.BODY_NOT_MATCH.getResultCode(),e.getMessage());
        }
    }

    @Override
    public void saveAccountNumber(AccountNumber accountNumber) {
          this.baseMapper.insert(accountNumber);
    }
}
